<template>
  <div class="activity_detail">
    <acti-detail-nav></acti-detail-nav>
    <acti-detail-view :activityData="activityData"></acti-detail-view>
    <acti-detail-buttom :startTime="startTime" :acInfo="actiInfo"></acti-detail-buttom>
  </div>
</template>

<script>
import {getActivityGuidanceInfo} from '@/api/activity'
import actiDetailNav  from './child/actiDetailNav.vue'
import actiDetailView from './child/actiDetailSurvey.vue'
import actiDetailButtom from './child/actiDetailButtom.vue'

export default {
  data(){
    return {
      activityData:{
        product: {
          product_description: '',
          product_tags: []
        }
      },
      startTime:0,
      actiInfo:{
        activity_id:'',
        product_id:'',
      }
    }
  },
  components:{
    actiDetailNav,
    actiDetailView,
    actiDetailButtom
  },
  created(){
    this.getActiviInfo()
  },
  methods:{
    getActiviInfo(){
      let t = parseInt(this.$route.query.q);
       getActivityGuidanceInfo(t).then(res=>{
        this.activityData = res.data
        this.actiInfo.activity_id = res.data.activity_id
        this.actiInfo.product_id = res.data.product.ID
        this.$store.dispatch('getActiInfo',this.actiInfo)
        this.startTime = res.data.start_time;
        let q = new Date(this.startTime)
        let q1 = new Date();
        let s1 = this.startTime.substring(0,4);
        let s2 = this.startTime.substring(5,7);
        let t2 = parseInt(s2)-1;
        let s3 = this.startTime.substring(8,10);
        let s4 = this.startTime.substring(11,13);
        let s5 = this.startTime.substring(14,16);
        let s6 = this.startTime.substring(17,19);
        let endTime = new Date(s1,t2,s3,s4,s5,s6);
        let startTime = new Date()
        if(endTime-startTime <=0){
          this.startTime = 0;
        }else {
          let day = Math.floor((endTime - startTime) / 1000 / 60 / 60 / 24)
          let hour = Math.floor((endTime - startTime) / 1000 / 60 / 60)
          let minute  = Math.floor((endTime - startTime) / 1000 / 60)
          let second = Math.floor((endTime - startTime) / 1000)
          this.startTime = (60*1000 * minute + 60*1000*60*hour)+3000 + second*60
        }
      })
    }    
  }
}
</script>

<style lang="less">

</style>